package com.newsmanagement.common;

import java.util.List;

public class Page {

	/**
	 * 总条数
	 */
	private int total;
	/**
	 * 查询的数据
	 */
	private List<?> list;
	
	/**
	 * 当前页数
	 */
	private int pageCount=1;
	
	/**
	 * 总页数
	 */
	private int totalPage;

	/**
	 * 显示条数
	 */
	private int showSize;

	/**
	 * 起始数据条数
	 */
	private int startPage;

	/**
	 * 取几条数据条数
	 */
	private int endPage;

	private Object rows;
	
	private int page;

	public Page(int total, int pageCount, int showSize) {

		//总条数
		total = null != list && list.size() > Constants.INT_ZERO ? list.size() : Constants.INT_ZERO;
		this.total = total;

		//当前页数
		this.pageCount = pageCount > Constants.INT_ZERO ? pageCount : Constants.INT_ONE;

		//显示条数
		this.showSize = showSize > Constants.INT_ONE ? showSize : Constants.INT_TWENTY;

		//总页数
		if (total % showSize == Constants.INT_ZERO){
			this.totalPage = total/showSize;
		}else{
			this.totalPage = total/showSize + Constants.INT_ZERO;
		}
		if (Constants.INT_ZERO == totalPage){
			this.totalPage = Constants.INT_ONE;
		}

		//起始数据条数
		this.startPage = (pageCount - Constants.INT_ONE) * showSize ;
		this.endPage = pageCount * showSize;

	}

	public Page(int total, List<?> list, int pageCount, int showSize) {

		//总条数
		total = null != list && list.size() > Constants.INT_ZERO ? list.size() : Constants.INT_ZERO;
		this.total = total;

		//当前页数
		this.pageCount = pageCount > Constants.INT_ZERO ? pageCount : Constants.INT_ONE;

		//显示条数
		this.showSize = showSize > Constants.INT_ONE ? showSize : Constants.INT_TWENTY;

		//总页数
		if (total % showSize == Constants.INT_ZERO){
			this.totalPage = total/showSize;
		}else{
			this.totalPage = total/showSize + Constants.INT_ZERO;
		}
		if (Constants.INT_ZERO == totalPage){
			this.totalPage = Constants.INT_ONE;
		}

		//起始数据条数
		int startPage = (pageCount - Constants.INT_ONE) * showSize ;
		int endPage = pageCount * showSize - Constants.INT_ONE;
		this.list = list.subList(startPage ,endPage);

	}

	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}

	public int getShowSize() {
		return showSize;
	}
	public void setShowSize(int showSize) {
		this.showSize = showSize;
	}
	public List<?> getList() {
		return list;
	}
	public void setList(List<?> list) {
		this.list = list;
	}
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	public int getPageCount() {
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public Object getRows() {
		return rows;
	}
	public void setRows(Object rows) {
		this.rows = rows;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}

	public int getStartPage() {
		return startPage;
	}

	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}

	public int getEndPage() {
		return endPage;
	}

	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	@Override
	public String toString() {
		return "Page{" +
				"total=" + total +
				", list=" + list +
				", pageCount=" + pageCount +
				", totalPage=" + totalPage +
				", showSize=" + showSize +
				", startPage=" + startPage +
				", endPage=" + endPage +
				", rows=" + rows +
				", page=" + page +
				'}';
	}
}
